package cn.xspace.module.other.http; 

import org.json.JSONObject;

import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;


public class HttpWorkNet<T> {
	private Context context;
	private String urlKey;
	private AsyncTask<Object, Object, Object> asyncTask;

	public HttpWorkNet(Context context, String urlKey, AsyncTask<Object, Object, Object> asyncTask) {
		this.context = context;
		this.urlKey = urlKey;
		this.asyncTask = asyncTask;
	}

	public void sendData(JSONObject requestObj) {
		Log.i("HttpWorkNet", "HttpWorkNet sendData urlKey:"+urlKey+" requestObj:"+requestObj);
		RequestQueue mQueue = Volley.newRequestQueue(context);
		mQueue.add(new JsonObjectRequest(Method.POST,  urlKey, requestObj, new Listener<JSONObject>() {
			public void onResponse(JSONObject response) {
				Log.i("HttpWorkNet", "onResponse response:"+response);
				asyncTask.execute((Object) context, (Object) response);
			}
		}, new ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError error) {
				Log.i("HttpWorkNet", "onErrorResponse error:"+error);
				asyncTask.execute((Object) context, (Object) error);
			}
		}));
		mQueue.start();
	}
 
	 
}